const { config } = require("@vue/test-utils");

const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  }
}

//获取所有用户信息
const allUser = {
  list: [
    { 
      userName: '1900130301', 
      nickName: '戴怡凡', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130302', 
      nickName: '曾小龙', 
      admissionYear: '2019.9.1',
      sex: '男', 
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130303', 
      nickName: '贺斌', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130304', 
      nickName: '胡峻', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130305', 
      nickName: '徐文海', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130306', 
      nickName: '吴德怀', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130307', 
      nickName: '邓响芳', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130308', 
      nickName: '张伟凡', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130309', 
      nickName: '刘进', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130310', 
      nickName: '邓联龙', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130311', 
      nickName: '徐江涛', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130312', 
      nickName: '邹鹏', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130313', 
      nickName: '刘杰', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130314', 
      nickName: '李嘉祥', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
    { 
      userName: '1900130315', 
      nickName: '朱梦龙', 
      sex: '男', 
      admissionYear: '2019.9.1',
      classId: '1903', 
      room: '504', 
      nationalityId: '汉族', 
      birthplaceId: '湖南', 
      academicYear: '四年', 
      culturalLevelId: '本科', 
      isPay: true, 
      isDisabled: '是', 
      isDisabledMode: '是' 
    },
  ],
  total: 15,
}

const userDetail = { 
  userName: '1900130302', 
  nickName: '曾小龙',
  idCard: '身份证',
  sex: '男', 
  classId: '1903', 
  room: '504', 
  dateOfBirth: '2001.7.14',
  telephone: '15343286965',
  nationalityId: '汉族', 
  birthplaceId: '湖南', 
  academicYear: '四年', 
  admissionYear: '2019',
  email: '1513107860@qq.com',
  politicalStatusId: '党员',
  area: '娄底',
  homeAddress: '湖南娄底',
  culturalLevelId: '本科', 
  isPay: true, 
  isDisabled: '是', 
  isDisabledMode: '是' 
}

var addUser = [];

module.exports = [
  // user login
  {
    url: '/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      // const token = tokens[username]
      const token = tokens['admin'];

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.',
        }
      }

      return {
        code: 20000,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      // if (!info) {
      //   return {
      //     code: 50008,
      //     message: 'Login failed, unable to get user details.'
      //   }
      // }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user search
  {
    url: '/user/search',
    type: 'post',
    response: config => {
      let { pageSize, pageNum } = config.body
      return {
        code: 20000,
        data: allUser
      }
    }
  },

  // user info
  {
    url: '/user/info',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user add 添加用户
  {
    url: '/user/add',
    type: 'post',
    response: config => {
      let addUserData = config.body;
      addUser.push(addUserData);
      return {
        code: 20000,
        data: config.body
      }
    }
  },

  // user updateInfo 修改用户信息
  {
    url: '/user/updateInfo',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user get 获取所有用户
  {
    url: '/user/get',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user sendVerifyCodeByEmail 获取验证码
  {
    url: '/user/sendVerifyCodeByEmail',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user verifyUsernamePassword 获取验证码
  {
    url: '/user/verifyUsernamePassword',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user verifyCode 校验验证码
  {
    url: '/user/verifyCode',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user updatePassword 修改密码
  {
    url: '/user/updatePassword',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user updateIsDisabled 修改禁用
  {
    url: '/user/updateIsDisabled',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user updateIsDisabledMode 修改禁用
  {
    url: '/user/updateIsDisabledMode',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user updateUserInfoByUserList 修改用户——用户列表功能
  {
    url: '/user/updateUserInfoByUserList',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  // user getUserById 通过id获取用户信息
  {
    url: '/user/userGetById',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: userDetail
      }
    }
  },
]
